<!DOCTYPE HTML>
<html>
<head>
<include file="Public:head" />
</head>
<body>
<!--main-->
<div class="midder">
<h2>{$title}</h2> 
<div id="listInfo">
  <div class="form2">
  	 <p><b>自动升级：</b>升级功能会自动下载升级包到/Data/upate/download/目录下，并自动完成解压、文件可写权限判断、文件覆盖、数据库更新等操作。优点是一键完成，方便快捷。缺点是如果文件写权限不足，会有些文件覆盖失败。</p>
  	 <p><b>手工下载：</b>需要站长自行下载升级包，并按升级包中的readme.txt文件中操作步骤自行操作更新。</p>
  	 <p><b>注意事项：</b>升级前请注意备份好文件和数据库，特别是配置文件Apps/Common/Conf和/Data目录下的用户数据。</p>
  	 <if condition="$noWritable">
  	 <ul>
  	 	<li class="message">提示：以下目录或文件没有可写权限，无法使用自动升级功能；请设置以下目录权限为 777 可写</li>	
  	 	<li class="message">
  	 	<volist name='noWritable' id='vo'>
  	 	./{$vo} 目录&nbsp;&nbsp;&nbsp;&nbsp;
  	 	</volist>
  	 	</li>	
  	 </ul>
  	 </if>
  </div>
</div>

<div id="showInfomation"></div>

</div>

<script type="text/javascript">
var step = "{:$_GET['step']}";
if(step=='isDownBefore'){
    var packageName = "";
    var key = "";
    isDownBefore(packageName, key)
}else if(step=='unzipPackage'){
    unzipPackage();
}else if(step=='checkFileIsWritable'){
    checkFileIsWritable();
}else if(step=='copyFileToProject'){
    copyFileToProject();
}else if(step=='dealsql'){
    dealsql();
}else if(step=='finishUpate'){
    finishUpate();	
}else{
    checkVersion();
}

function checkVersion(){
    showMsg('更新版本查询中');
    var postURL = "{:U('admin/update/step01_checkversionbyajax')}";
	$.post(postURL, {id:1}, function(res){ 
	    $('#showInfomation').html(res);
	},'html');
}
function isDownBefore(packageName, key){
	showMsg('判断是否已经手工下载更新包');    
    var postURL = "{:U('admin/update/step02_isdownbefore')}&packageName=" + packageName + "&key=" + key;
	$.post(postURL, {id:1}, function(res){
	    if(res==0){
		   showMsg('您还没有下载更新包，正在自动下载更新包中');    
		   downloadPackage(packageName, key);
		}else{
		   showMsg('您已经下载更新包，正在升级中');   
		   window.location.href="{:U('admin/update/index')}&step=dealsql";
		}
	});
}
function downloadPackage(packageName, key){
	showMsg('下载更新包中...请稍等');    
    var postURL = "{:U('admin/update/step03_download')}&packageName=" + packageName + "&key=" + key;
	$.post(postURL, {id:1}, function(res){
	    if(res==0){
		   $('#showInfomation').html('<div id="listInfo"><div class="content"><h3 class="center">更新包下载失败，请检查你的网络连接是否正常</h3></div></div>');
		}else{
		   window.location.href="{:U('admin/update/index')}&step=unzipPackage&packageName=" + packageName;
		}
	});
}
function unzipPackage(){
    showMsg('更新包解压中');
    var packageName = "{:$_GET['packageName']}";
	var postURL = "{:U('admin/update/step04_unzippackage')}&packageName=" + packageName;
	$.post(postURL, {id:1}, function(res){
	    if(res!=1){
		   $('#showInfomation').html(res);
		}else{
		   window.location.href="{:U('admin/update/index')}&step=checkFileIsWritable&packageName=" + packageName;
		}
	});	
}

function checkFileIsWritable(){
    showMsg('判断系统文件的可写权限');
	var packageName = "{:$_GET['packageName']}";
	var postURL = "{:U('admin/update/step05_checkfileiswritable')}&packageName=" + packageName;
	$.post(postURL, {id:1}, function(res){
         if(res!=1){
		   $('#showInfomation').html(res);
		}else{
		   window.location.href="{:U('admin/update/index')}&step=copyFileToProject";
		}
	});	
}
function copyFileToProject(){
    showMsg('更新系统文件中');    
	var postURL = "{:U('admin/update/step06_overwritten')}";
	$.post(postURL, {id:1}, function(res){
         if(res!=1){
		   $('#showInfomation').html(res);
		}else{
		   window.location.href="{:U('admin/update/index')}&step=dealsql";
		}
	});	
}

function dealsql(){
    showMsg('更新数据库数据中');    
	var postURL = "{:U('admin/update/step07_dealsql')}";
	$.post(postURL, {id:1}, function(res){
	    window.location.href="{:U('admin/update/index')}&step=finishUpate";
	});	
}

function finishUpate(){
    showMsg('正在完成升级操作');    
	var postURL = "{:U('admin/update/step08_finishupate')}";
	$.post(postURL, {id:1}, function(res){
	    if(res==1){
		   window.location.href="{:U('admin/update/upateall')}";
		}else{
		   window.location.href="{:U('admin/update/index')}";
		}
	});
}
function showMsg(msg){
    $('#showInfomation').html('<div id="listInfo"><div class="contentbox"><h2>'+msg+'...</h2></div></div>');
}
function needUpateOther(version, title){
    alert('请先升级版本[V' + version + ']  [' + title + '] 这个升级包后才能更新此升级包');
}
</script>
</body>
</html>